#if !defined NES_GLOBALS_INCLUDED
#include "include/nes/nes_globals.inl"
#endif

#if !defined NES_SAVE_INCLUDED
#include "include/nes/nes_save.inl"
#endif
#if !defined NES_REGISTER_INCLUDED
#include "include/nes/nes_register.inl"
#endif

#define NES_MENUS_INCLUDED 1
enum _:MENU_ITEMS
{
	MI_HELP = 1,
	MI_SAVE,
	MI_REGISTER_NAME
}

public showMenu(id){
	new title[64];
	new info[2];
	formatex(title, charsmax(title), "%L", id, "TITLE_MENU");
	new menu = menu_create(title, "mainMenuHandler");
	formatex(title, charsmax(title), "%L", id, "TITLE_MENU_HELP");
	info[0] = MI_HELP;
	menu_additem(menu, title, info, 0);
	
	formatex(title, charsmax(title), "%L", id, "TITLE_MENU_SAVE");
	info[0] = MI_SAVE;
	menu_additem(menu, title, info, 0);
	
	formatex(title, charsmax(title), "%L", id, "TITLE_MENU_REGISTER_NAME");
	info[0] = MI_REGISTER_NAME;
	menu_additem(menu, title, info, 0);
	
	return PLUGIN_HANDLED;
}


public mainMenuHandler(id, menu, item){
	if(item != MENU_EXIT) {
		new info[2], acc, call;
		menu_item_getinfo(menu, item, acc, info, charsmax(info), _,_, call);
		switch(info[0]){
			case MI_HELP: showHelp( id );
			case MI_SAVE: saveAll(id);
			case MI_REGISTER_NAME: registerName(id);
		}
	}
	menu_destroy(menu);
}

public showHelp(id) {
	new motdFile[32];
	formatex(motdFile, charsmax(motdFile), "%L", id, "MOTD_HELP_FILE");
	show_motd(id, motdFile);
}

public registerName(id){
	new info[16];
	get_user_info(id, const_NES_PASS_FLD, info, charsmax(info));
	if(info[0]){
		client_print(id, print_chat, "%L", LANG_PLAYER, "USER_ALREADY_REGISTERED");
	} else {
		client_cmd(id, "messagemode register_name");
	}
}

public registerName2(id){
	new args[16];
	read_argv(1, args, charsmax(args));
	remove_quotes(args);
	nvault_set(gVaultNicks, gPlayerInfo[id][PI_KEY], args);
	client_print(id, print_chat, "%L", LANG_PLAYER, "NICK_REGISTERED", gPlayerInfo[id][PI_KEY], args);
	client_print(id, print_chat, "%L", LANG_PLAYER, "NICK_REGISTERED2", args);
}
